import JDBCunit.Jdbcs;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class JdbcTest05 {
    public static void main(String[] args) {
        //JDBC      增删改查
        Connection cn = null;
        PreparedStatement ps = null;//增
        PreparedStatement ps1 = null;//delete
        PreparedStatement ps2 = null;//update
        try {
            cn = Jdbcs.jC();

            ps = cn.prepareStatement("insert into t_user (uname,psd)values(?,?)");
            ps1 = cn.prepareStatement("delete from t_user where uname = ?");
            ps2 = cn.prepareStatement("update t_user set psd = ? where uname = ?");
            //增：insert
            ps.setString(1,"迪迦奥特曼");
            ps.setString(2,"awehanse12");
            //删 delete
            ps1.setString(1,"lisi");
            //改 update
            ps2.setString(1,"密码已泄露");
            ps2.setString(2,"迪迦奥特曼");


            int count = ps.executeUpdate();
            int count1 = ps1.executeUpdate();
            int count2 = ps2.executeUpdate();

            System.out.println(count == 1 ? "添加记录成功":"添加记录失败");
            System.out.println(count1 == 1 ? "删除记录成功":"删除记录失败");
            System.out.println(count2 == 1 ? "修改记录成功":"修改记录失败");



        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                Jdbcs.jClose(null,ps,cn);
            } catch (SQLException e) {
                e.printStackTrace();
            }

        }
    }
}
